<?php
/**
 * Conversations - A lightweight BB for Xaraya
 *
 * @package modules
 * @copyright (C) 2003-2006 The Digital Development Foundation.
 * @license GPL {@link http://www.gnu.org/licenses/gpl.html}
 * @link http://www.xaraya.com
 *
 * @subpackage conversations
 * @link http://xaraya.com/index.php/release/760.html
 * @author John Cox
*/
/** 
 * Modify a Post
 * 
 * @package Xaraya eXtensible Management System
 * @copyright (C) 2005 by the Xaraya Development Team.
 * @license GPL {@link http://www.gnu.org/licenses/gpl.html}
 * @link http://www.xaraya.org
 *
*/

/**
 * @author John Cox
 * @author jojodee
 * add new forum topic
 */

function conversations_user_modify_post()
{

    if (!xarVarFetch('modify_post', 'str:1', $post, '', XARVAR_NOT_REQUIRED)) return;
    if (!xarVarFetch('modify_postid', 'int:0:', $postid, '', XARVAR_DONT_SET)) return;
    if (!xarVarFetch('modify_uid', 'int:0:', $uid, '', XARVAR_DONT_SET)) return;
    

    // This should be relatively simple.  The only issue will be the returning back to
    // the page with the AJAX call.
    
    // User Info, we'll use this quite a bit
    // Let's set all of the variables.
    $user = xarUserGetVar('uid');
    $udisplay_name = xarUserGetVar('name');
    $timestamp = time();


    // We probably need some security sanity here
    if (!xarSecurityCheck('Modcon', 0)) {
        // No Privs, Hows about this is my comment?
        // FIXME: we have not checked whether this is a comment! Is 'edit' phase really supported?
        if ($user != $uid) {
            // Nope?  Lets return
            // TODO: needs to be templated.
            $message = xarML('You do not have access to modify this reply');
            return $message;
        }
    } else {
        if (!xarSecurityCheck('Postcon', 1)) return;
    }
    
    $data = array();
    
    // We should probably say that the post was modified, and by who...
    

    // We don't need to play with the tag, so moving on...
    // We should just have to send it to the modify function...
    
    xarModAPIFunc('conversations', 'user', 'updatepost', array(
                                        'text'   => $post,
                                        'postid' => $postid,
                                        'timestamp' => $timestamp));
                                        
    // Transform the post
    $post = xarModCallHooks('item', 'transform', 1, $post, 'conversations', 2);
    
    // Just need to return the post really...
    return $post;
}

?>